package top.pmwly.oauth2_jwt.controller;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * @author Herther
 * @version 1.0.0
 * @ClassName UserController.java
 * @Description 用户控制
 * @createTime 2021年08月21日 17:52:00
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 获取当前对象
     * @param request
     * @return
     */
    @RequestMapping("/getDetails")
    public Object getDetails(HttpServletRequest request){
        //从请求头中获取token
        String token = request.getHeader("authorization");
        System.out.println(token);
        //解析token
        Claims body = Jwts.parser()
                //密钥
                .setSigningKey("hello_word".getBytes(StandardCharsets.UTF_8))
                .parseClaimsJws(token)
                .getBody();
        return body;

    }

}
